#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int m, n;
    int dx[4] = { 0, 0, 1, -1 };
    int dy[4] = { 1, -1, 0, 0 };
    int ret;
    int memo[201][201];
    int longestIncreasingPath(vector<vector<int>>& mat) {
        m = mat.size(), n = mat[0].size();

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {

                ret = max(ret, dfs(mat, i, j));


            }
        }
        return ret;
    }
    int dfs(vector<vector<int>>& mat, int i, int j) {
        if (memo[i][j]) return memo[i][j];
        int ret = 1;
        for (int k = 0; k < 4; k++) {
            int x = i + dx[k], y = j + dy[k];
            if (x >= 0 && x < m && y >= 0 && y < n && mat[x][y] > mat[i][j]) {

                ret = max(ret, dfs(mat, x, y) + 1);
            }
        }
        memo[i][j] = ret;
        return ret;
        //  memo[i][j]=path;
    }
};